/**
* This is about <code>org.shoebox.guacamole.materials.AtlasMaterial</code>.
* {@link www.hyperfiction.fr}
* @author shoe[box]
*/

package org.shoebox.guacamole.materials {

	import org.shoebox.utils.logger.Logger;
	import flash.display3D.textures.Texture;
	import flash.utils.Dictionary;
	
	/**
	* org.shoebox.guacamole.materials.AtlasMaterial
	* @author shoebox
	*/
	public class AtlasMaterial extends BitmapMaterial{
		
		protected var _dRegionsIDs			: Dictionary = new Dictionary( false );
		protected var _vRegions			: Vector.<TextureRegion>;
		
		// -------o constructor
		
			/**
			* Constructor of the GridMaterial class
			*
			* @public
			* @return	void
			*/
			public function AtlasMaterial( tTexture : Texture , sourceWidth : int = 0 , sourceHeight : int = 0 , bRepeat : Boolean = false , name : String = null ) : void {
				super( tTexture , sourceWidth , sourceHeight , bRepeat , name );
				_vRegions = new Vector.<TextureRegion>( );
			}

		// -------o public
			
			/**
			* addRegion function
			* @public
			* @param 
			* @return
			*/
			final public function addRegion( sRegionName : String , dx : Number , dy : Number , dw : Number , dh : Number ) : void {
				
				var 	oReg : TextureRegion = new TextureRegion( sRegionName , this );
						oReg.dx = Number( dx ) / sourceWidth;
						oReg.dy = Number( dy ) / sourceHeight;
						oReg.width = Number( dw ) / sourceWidth;
						oReg.height = Number( dh ) / sourceHeight;
				
				_dRegionsIDs[ sRegionName ] = _vRegions.push( oReg ) - 1;
				
			}
			
			/**
			* getRegion function
			* @public
			* @param 
			* @return
			*/
			final public function getRegion( sRegionName : String ) : TextureRegion {
				return _vRegions[ _dRegionsIDs[ sRegionName ] ];
			}
			
		// -------o protected

		// -------o misc

			public static function trc(...args : *) : void {
				Logger.log(AtlasMaterial, args);
			}
	}
}
